<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form">
    <input name="id" id="id" type="hidden"/>
    <br/>
    <div class="layui-form-item">
        <label class="layui-form-label">原密码:</label>
        <div class="layui-input-inline">
            <input type="password" name="stdPwd" id="stdPwd" lay-verify="required" placeholder="请输入密码"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">现密码:</label>
        <div class="layui-input-inline">
            <input type="password" name="pwd" id="pwd" lay-verify="required" placeholder="请输入密码"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码:</label>
        <div class="layui-input-inline">
            <input type="password" name="pwd2" id="pwd2" lay-verify="required" placeholder="再次确认密码"
                   autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <button class="layui-btn" id="formSubmit" lay-submit="" lay-filter="formSubmit" style="display: none">立即提交</button>
</form>
<script th:replace="/common/inc::incJs"></script>
<script>
    var form = layui.form;
    var successCallback;

    //监听提交
    form.on('submit(formSubmit)', function (data) {
        if (data.field.pwd == data.field.pwd2) {
            $.post('/backend/security/sysUser/changePwd', {
                stdPwd: $("#stdPwd").val(),
                pwd: $("#pwd").val()
            }, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                } else {
                    layer.msg('密码修改成功');
                    successCallback && successCallback();
                }
            });
        } else {
            layer.msg('两次密码不相同');
            return false;
        }
        return false;
    });

    var formSubmit = function (callback) {
        successCallback = callback;
        $("#formSubmit").click();
    };


    $(function () {

    })
</script>
</body>
</html>